﻿using System;
using System.Windows;
using YSGetLatest.Properties;

namespace YSGetLatest
{
	/// <summary>
	/// Interaction logic for OptionsWindow.xaml
	/// </summary>
	public partial class OptionsWindow : Window
	{
		/// <summary>
		/// 
		/// </summary>
		public OptionsWindow()
		{
			InitializeComponent();
		}

		private void ButtonBrowse_Click(object sender, RoutedEventArgs e)
		{
			// Create OpenFileDialog
			Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

			dlg.Title = "Select TF.exe location";
			dlg.InitialDirectory = Settings.Default.TFLocation;
			dlg.DefaultExt = "*.exe";
			dlg.Filter = "TF.exe|tf.exe";

			Nullable<bool> result = dlg.ShowDialog();

			if (result.HasValue && result.Value)
			{
				textBoxTfPath.Text = System.IO.Path.GetDirectoryName(dlg.FileName);
			}
		}

		private void ButtonResetDefault_Click(object sender, RoutedEventArgs e)
		{
			Settings.Default.Reset();
			textBoxTfPath.Text = Settings.Default.TFLocation;
		}

		private void Window_Loaded(object sender, RoutedEventArgs e)
		{
			textBoxTfPath.Text = Settings.Default.TFLocation;
		}

		private void ButtonOK_Click(object sender, RoutedEventArgs e)
		{
			Settings.Default.TFLocation = textBoxTfPath.Text;
			Settings.Default.Save();
			DialogResult = true;
			Close();
		}
	}
}
